<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>MyPromise test</title>
</head>
<body>
    <script>
    function err(error) {
        console.log('err: ' + error.message);
        throw error;
    }


    // 异步
    function nextTick(fn) {
        setTimeout(function() {
            try {
                fn();
            }
            catch (error) {
                console.log('err at nextTick: ' + error.message);
                err(error);
            }
        }, 0);
    }
    // test
    var that = this;

    nextTick(function() {
        a.x;
    });

    

    function F() {
        this.b = 1;

        this.f = function() {
            console.log('this.b = ' + this.b);
        }

        function fn() {
            console.log('this.b = ' + this.b);
        }
        fn();
    }
    F.prototype.pf = function() {
        console.log('this.b = ' + this.b);
    }
    F.prototype.pf2 = function(obj) {
        console.log(this === obj);
    }

    var f = new F();
    f.f();
    f.pf();
    f.pf2(f);

    var p = new Promise(function(resolve, reject) {
        resolve(1);
    });
    var p1 = p.then(alert, alert);
    var p2 = p1.then(alert, alert);
    console.log(p1 === p2);
    </script>
</body>
</html>